<?php
	class baigioithieudb
	{
		public function Them($TieuDe = "",
							 $NoiDung = "",
							 $XuatBan = 0)
		{
			$sql = "INSERT INTO baigioithieu(TieuDe, NoiDung, XuatBan) 
					VALUES(".dataservice::QuoteSmart($TieuDe).",
							 "."'".$NoiDung."', 
						   ".dataservice::QuoteSmart($XuatBan).")";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
	
		public function CapNhatXuatBanBaiGioiThieu($MaBaiGioiThieu = 0, $XuatBan = 0)
		{
			$sql = "update baigioithieu 
					set 
						XuatBan = ".dataservice::QuoteSmart($XuatBan)." 
					where 
						MaBaiGioiThieu = ".dataservice::QuoteSmart($MaBaiGioiThieu);		
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach($MaBaiGioiThieu = 0, 
									$TieuDe = "", 
									$NoiDung = "", 
									$XuatBan = 0)
		{	
			$sql = "SELECT * 
					FROM baigioithieu 
					WHERE 1";
			
			if($MaBaiGioiThieu > 0)
				$sql .= " AND MaBaiGioiThieu = $MaBaiGioiThieu";
				
			if($TieuDe != "")
				$sql .= " AND TieuDe = '$TieuDe'";
			
			if($NoiDung != "")
				$sql .= " AND NoiDung = '$NoiDung'";
				
			if($XuatBan > 0)
				$sql .= " AND XuatBan = $XuatBan";
					
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function CapNhat($MaBaiGioiThieu = 0, 
								$TieuDe = '', 
								$NoiDung = '')
		{
			$sql = "update baigioithieu 
					set TieuDe = ".dataservice::QuoteSmart($TieuDe).", 
						NoiDung = '".$NoiDung."' 
					where 
						MaBaiGioiThieu = ".dataservice::QuoteSmart($MaBaiGioiThieu);		
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		

		public function Xoa($MaBaiGioiThieu = 0)
		{
			$sql = 'delete from baigioithieu where (1)';
			
			if ($MaBaiGioiThieu > 0)
				$sql .= ' and MaBaiGioiThieu = '.dataservice::QuoteSmart($MaBaiGioiThieu);			
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function XoaTatCa()
		{
			$sql = "DELETE FROM baigioithieu";			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
	}
?>